<?php
class CpyInfo extends CI_Model {
	public $cpy_name;
	public $cpy_address_1;
	public $cpy_address_2;
	public $cpy_tel;
	public $cpy_fax;
	public $cpy_email;
	
	function __construct() {
		parent::__construct ();
		$this->load->database ();
		$this->load->model ( "vo/CpyInfoVo" );
	}
	
	function getCpyInfoById($id, $au = FALSE) {
		$this->db->where ( "fun_cpy_id", $id );
		$query = $this->db->get ( 'fun_cpy' );
		
		foreach ( $query->result () as $cpyObj ) {
			$this->CpyInfoVo->setCpyId ( $id );
			$this->CpyInfoVo->setCpyName ( $cpyObj->cpy_name );
			$this->CpyInfoVo->setCpyAddr1 ( $cpyObj->cpy_address_1 );
			$this->CpyInfoVo->setCpyAddr2 ( $cpyObj->cpy_address_2 );
			$this->CpyInfoVo->setCpyTel ( $cpyObj->cpy_tel );
			$this->CpyInfoVo->setCpyFax ( $cpyObj->cpy_fax );
			$this->CpyInfoVo->setCpyEmail ( $cpyObj->cpy_email );
			$this->CpyInfoVo->setCpyPhoto ( $cpyObj->cpy_photo );
			if ($au) {
				$cpy_au = $cpyObj->cpy_au;
				$this->CpyInfoVo->setCpyAu ( $cpy_au );
			}
		}
		$query->free_result ();
		return $this->CpyInfoVo;
	}
	
	function save($cpyInfoVo) {
		$this->cpy_name = $cpyInfoVo->getCpyName ();
		$this->cpy_address_1 = $cpyInfoVo->getCpyAddr1 ();
		$this->cpy_address_2 = $cpyInfoVo->getCpyAddr2 ();
		$this->cpy_tel = $cpyInfoVo->getCpyTel ();
		$this->cpy_fax = $cpyInfoVo->getCpyFax ();
		$this->cpy_email = $cpyInfoVo->getCpyEmail ();
		
		if ($this->session->userdata ( USER_KEY ))
			$this->db->insert ( 'fun_cpy', $this );
	}
	
	function update($cpyInfoVo) {
		$this->cpy_name = $cpyInfoVo->getCpyName ();
		$this->cpy_address_1 = $cpyInfoVo->getCpyAddr1 ();
		$this->cpy_address_2 = $cpyInfoVo->getCpyAddr2 ();
		$this->cpy_tel = $cpyInfoVo->getCpyTel ();
		$this->cpy_fax = $cpyInfoVo->getCpyFax ();
		$this->cpy_email = $cpyInfoVo->getCpyEmail ();
		$this->cpy_au = $cpyInfoVo->getCpyAu ();
		
		$this->db->where ( "fun_cpy_id", $cpyInfoVo->getCpyId () );
		
		if ($this->session->userdata ( USER_KEY ))
			$this->db->update ( "fun_cpy", $this );
	}

}

?>